package org.example.admincontroller;

import lombok.extern.slf4j.Slf4j;
import org.example.adminservice.OrderService;
import org.example.pojo.Result;
import org.example.pojo.admindto.OrderCheckDTO;
import org.example.pojo.admindto.SaleTableDTO;
import org.example.pojo.adminvo.OrderCheckVO;
import org.example.pojo.adminvo.SaleTableVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/order")
public class OrderCheckController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/list")
    public Result getOrder(@RequestParam(defaultValue = "1") int page,
                           @RequestParam(defaultValue = "10") int pageSize,
                           @RequestParam(value = "username", required = false) String username,
                           @RequestParam(value = "goodname", required = false) String goodname,
                           @RequestParam(value = "state", required = false) Integer state
                           ) {
        OrderCheckDTO orderCheckDTO = new OrderCheckDTO(page,pageSize,username,goodname,state);
        OrderCheckVO orderCheckVO = new OrderCheckVO();
        if(orderCheckDTO.getPage()==null){
            orderCheckDTO.setPage(1);
        }
        if(orderCheckDTO.getPageSize()==null){
            orderCheckDTO.setPageSize(10);
        }
        orderCheckVO.setPageBean(orderService.getAllOrders(orderCheckDTO));
        return Result.success(orderCheckVO);
    }

    @GetMapping("/table")
    public Result getOrderTable(@RequestParam(value = "goodid", required = false) int goodid,
                                @RequestParam(value = "goodname", required = false) String goodname) {
        SaleTableDTO saleTableDTO = new SaleTableDTO(goodid,goodname);
        List<SaleTableVO> saleTableVOList = orderService.getSaleTableVO(saleTableDTO);
        return Result.success(saleTableVOList);
    }
}
